import java.io.IOException;
import java.net.*;
import java.util.LinkedList;
import java.util.Queue;


public class Port extends Thread
{
    private MacAddress physical;    //virtual
    private InetAddress local;    //virtual
    private InetAddress remote;   //real
    private int portNum;            //real
    private boolean running;//controls state of threads
    private Queue tQueue;	//transmit queue
    private Queue rQueue;	//receive queue
    private DatagramSocket socket;
    private InetAddress target;
    private int mtu;
    private int subnetMask;
    
    private RxEngine receive;
    private TxEngine transmit;
    
    // constructor
    public Port(int portNum, String ip, int subnetMask, int mtu) throws UnknownHostException, SocketException
    {
    	  	
        local = InetAddress.getByName(ip);
        this.mtu = mtu;
        this.subnetMask = subnetMask;
        
        socket = new DatagramSocket(portNum, local);
        
        //transmit = new TxEngine(socket);
       // receive = new RxEngine(this);
    
    }
    
    

    public Port() throws UnknownHostException
    {
        local = InetAddress.getLocalHost();
        running = true;
        tQueue = new LinkedList();
        rQueue = new LinkedList();
    }
   
    
    /**
     * Used for command close socket
     */
    public void close()
    {
        socket.close();
    }

    /**
     * Used for command disconenct socket
     */
    public void disconnect()
    {
    	socket.disconnect();
    }
    
    /**
     * Connects local port to a remote port
     * @param targetPort
     * @param targetIP
     * @throws UnknownHostException
     */
    public void connect(int targetPort, String targetIP) throws UnknownHostException
    {
        //connect add <local real port> <remote Real IP:port>
        socket.connect(InetAddress.getByName(targetIP), targetPort);
     }
    
  

    @Override
	public void run()
    {
        running = true;

        while (running == true)
        {
        }
    }

    public void halt()
    {
        running = false;
    }



}
